package com.baizhi.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

@Data
public class BzAdmin implements UserDetails {
    @TableId(value = "id",type = IdType.AUTO)
    private Integer id;
    /**
     * 用户名必须是username
     * 密码必须是password
     * 原因：SpringSecurity获取账号密码通过get方法
     * get方法名必须是 getUsername getPassword
     */
    private String username;
    private String password;
    private Integer status;

    @TableField(exist = false)
    private List<GrantedAuthority> authorities;

    /**
     * 获取授权信息
     *
     * ctrl+H 查看当前类的继承关系 接口的实现关系
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
